<?php
session_start();
require('check_login.php');
include(dirname(__FILE__) . '/config.php');
require_once('header.php');
require_once('contacts_lib.php');
if(isset($_GET['id'])){
$a_contact=get_contact_detail($_GET['id']);

}
if (isset($_POST['go'])){
update_contact($_POST);
}

?>

<!-- BEGIN CONTAINER -->
<div class="page-container">
	<!-- BEGIN SIDEBAR -->
	<?php require_once('left_menu.php'); ?>
	<!-- END SIDEBAR -->
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
			
			<!-- /.modal -->
			<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
			<!-- BEGIN STYLE CUSTOMIZER -->
			
			<!-- END STYLE CUSTOMIZER -->
			<!-- BEGIN PAGE HEADER-->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN PAGE TITLE & BREADCRUMB-->
					
					<ul class="page-breadcrumb breadcrumb">
						
						<li>
							<i class="fa fa-home"></i>
							<a href="dashboard.php">
								Trang chủ
							</a>
							<i class="fa fa-angle-right"></i>
						</li>
						<li>
							<a href="contacts.php">
								Danh sách đối tác
							</a>
							<i class="fa fa-angle-right"></i>
						</li>
						<li>
							<a href="edit_contact_detail.php?id=<?php echo $a_contact['id']?>">
								Sửa chi tiết
							</a>
							<i class="fa fa-angle-right"></i>
						</li>
						
					</ul>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
			</div>
			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->
			<div class="portlet box green">
									<div class="portlet-title">
										<div class="caption">
											<i class="fa fa-reorder"></i>Form nhập liệu
										</div>
										
									</div>
									<div class="portlet-body form">
										<!-- BEGIN FORM-->
										<form id ='form_add_contact' class="horizontal-form" method="post" action="edit_contact_detail.php">
											<div class="form-body">
												<h3 class="form-section">Thông tin cá nhân</h3>
												<div class="row">
													<div class="col-md-6">
														<div class="form-group">
															<label class="control-label">Họ
															<span class="required">*</span>
															</label>
															<input type="text" class="form-control" id="name" name="first_name" value="<?php echo (isset($a_contact['first_name']) ? $a_contact['first_name'] : '') ?>">
															<input type="hidden" name="id" value="<?php echo $a_contact['id'] ?>"/>
														</div>
													</div>
													<!--/span-->
													<div class="col-md-6">
														<div class="form-group">
															<label class="control-label">Tên
															<span class="required">*</span>
															</label>
															<input type="text"  class="form-control" id="lastName" name="last_name" value="<?php echo(isset($a_contact['last_name']) ? $a_contact['last_name'] : '') ?>">
															
														</div>
													</div>
													<!--/span-->
												</div>
												<!--/row-->
												<div class="row">
													<div class="col-md-6">
														<div class="form-group">
															<label class="control-label">Giới tính</label>
															<select name="sex" class="form-control">
																<option <?php echo (($a_contact['sex']==1) ? 'selected="selected"' : '') ?> value="1">Nam</option>
																<option <?php echo (($a_contact['sex']==0) ? 'selected="selected"' : '') ?> value="0">Nữ</option>
															</select>
															
														</div>
													</div>
													<!--/span-->
													<div class="col-md-6">
														<div class="form-group">
															<label class="control-label">Ngày sinh</label>
															<input type="text" name="birth_day" placeholder="dd/mm/yyyy" class="form-control" value="<?php echo (isset($a_contact['birth_day']) ? $a_contact['birth_day'] : '') ?>">
														</div>
													</div>
													<!--/span-->
												</div>
												<div class="row">
													<div class="col-md-6">
														<div class="form-group">
															<label class="control-label">Email</label>
															<input type="text" name="email" class="form-control" value="<?php  echo(isset($a_contact['email']) ? $a_contact['email'] : '') ?>">
															
														</div>
													</div>
													<!--/span-->
													<div class="col-md-6">
														<div class="form-group">
															<label class="control-label">Số điện thoại</label>
															<input type="text" name="phone" class="form-control" value="<?php echo(isset($a_contact['phone']) ? $a_contact['phone'] : '') ?>">
														</div>
													</div>
													<!--/span-->
												</div>
												<!--/row-->
												
												<!--/row-->
												<h3 class="form-section">Địa chỉ</h3>
												<div class="row">
													<div class="col-md-12">
														<div class="form-group">
														
														<textarea name="address" rows="3" class="form-control"><?php echo(isset($a_contact['address']) ? $a_contact['address'] : '') ?></textarea>
														</div>
													</div>
													
												</div>
												
												<!--/row-->
												
												<!--/row-->
												<h3 class="form-section">Mô tả chung</h3>
												<div class="row">
													<div class="col-md-12">
														<div class="form-group">
														
														<textarea name="description" rows="3" class="form-control"><?php echo(isset($a_contact['description']) ? $a_contact['description'] : '') ?></textarea>
														</div>
													</div>
													
												</div>
												
												<!--/row-->
												
											</div>
											<div class="form-actions right">
												<button class="btn default" type="button">Hủy</button>
												<button class="btn blue" type="submit" name="go"><i class="fa fa-check"></i> Lưu</button>
											</div>
										</form>
										<!-- END FORM-->
									</div>
								</div>
								<a class="btn default" id="auto_fire_when_edit_ok">
										 
								</a>
			<!-- END PAGE CONTENT -->
		</div>
	</div>
	<!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<?php 
require_once('footer.php');
require_once('common_script.php');
?>
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="assets/scripts/core/app.js"></script>
<script src="js/add_contact_validation.js"></script>
<script src="js/add_contact_alert_dialog.js"></script>
<script>
jQuery(document).ready(function() {       
   // initiate layout and plugins
   App.init();
   FormAddContactValidation.init();
   UIAlertDialogApi.init();
   <?php 
   if (isset($_POST['go'])){
	?>
	$('#auto_fire_when_edit_ok').click();
	
	<?php
	}
	?>
});
</script>
</body>
<!-- END BODY -->
</html>